package com.example.studentportrait.controller.admin.Assessment;

import com.example.studentportrait.domain.ResponseResult;
import com.example.studentportrait.domain.dto.ListAssessmentTypeDto;
import com.example.studentportrait.domain.entity.AssessmentType;
import com.example.studentportrait.service.AssessmentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/assessment")
public class AssessmentTpyeController {
    @Autowired
    private AssessmentTypeService assessmentTypeService;

    /**
     * 获取题型类型列表
     * @param page
     * @param size
     * @param listAssessmentTypeDto
     * @return
     */
    @GetMapping("/assessmentTypeList")
    public ResponseResult assessmentTypeList( @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, ListAssessmentTypeDto listAssessmentTypeDto) {

        return assessmentTypeService.assessentTypelist(page,size,listAssessmentTypeDto);
    }

    /**
     * 增加题型类型
     * @param assessmentType
     * @return
     */
    @PostMapping("addAssessmentType")
    public ResponseResult addAssessmentType(@RequestBody AssessmentType assessmentType) {
        if (assessmentType == null) {
            return ResponseResult.errorResult(500,"出现错误");
        }
        assessmentType.setCreateTime(new Date());
        assessmentType.setUpdateTime(new Date());

        return assessmentTypeService.addAssessmentType(assessmentType);
    }

    /**
     * 更新题型类型
     * @param assessmentType
     * @return
     */
    @PutMapping("updateAssessmentType")
    public ResponseResult<AssessmentType> updateAssessmentType(@RequestBody AssessmentType assessmentType){
        return assessmentTypeService.updateAssessmentType(assessmentType);
    }

    /**
     * 删除题型类型
     * @param id
     * @return
     */
    @DeleteMapping("deleteAssessmentType")
    public ResponseResult deleteAssessmentType(@RequestParam("id") Integer id) {
        return assessmentTypeService.deleteAssessmentType(id);
    }

    /**
     * 批量删除题型类型
     * @param ids
     * @return
     */
    @DeleteMapping("deleteAssessmentTypes")
    public ResponseResult deleteAssessmentTypes(@RequestBody List<Integer> ids){
        return assessmentTypeService.deleteAssessmentTypes(ids);
    }
}
